/**
 * Date：2017.05.13 星期六 下午
 * Function：路由配置 
 * E-mail：woaitianwen@qq.com
 * Author：zhouyulong
 */

"use strict";

var verifyToken = require('./api/middlewares/verifyToken');
var HomeController = require('./api/controllers/HomeController');
var BookController = require('./api/controllers/BookController');
var UserController = require('./api/controllers/UserController');
var CommentController = require('./api/controllers/CommentController');

//Routes
module.exports = function(app){

/** 书虫api接口 */
/********************* 
 * localhost:3000
 * *******************
 */

app.get('/api',verifyToken,HomeController.Index);

/********************* 
 * localhost:3000/book
 * *******************
 */
app.route('/api/book')
   .get(verifyToken,BookController.Index);

app.route('/api/book/:bookId')
   .get(verifyToken,BookController.ReadId);

     
/********************* 
 * localhost:3000/user
 * *******************
 */
app.route('/api/user')
   .get(verifyToken,UserController.all_users)
   .post(UserController.register);

app.route('/api/user/:UserId')
   .get(verifyToken,UserController.userId);

app.route('/api/auth')
   .post(UserController.auth_token);

//退出登录
app.route('/api/logout')
   .post(UserController.logout);

app.route('/api/comment')
   .get(CommentController.all_comments)
   .post(CommentController.create_comment);
   
/** 书虫web版 */
app.get('/',function(req, res){
    res.render('index', {title: '书虫首页'});
});
app.get('/home', function(req, res){
    res.render('home', {title: '欢迎页面'});
});
app.get('/login', function(req, res){
    res.render('login', {title: '登录页面'});
});
app.get('/signup', function(req, res){
    res.render('signup', {title: '注册页面'});
})
app.get('/contact', function(req, res){
    res.render('contact', {title: '联系页面'});
})


/**
 * 调用接口
 */
app.get('/test', function(req, res){
    res.render('test', {title: '调用接口页面'});
})

/** 后台管理PC版 */
app.get('/admin', function(req, res){
    res.render('admin/index',{title: '后台管理'});
})
/** 书虫wap版 */
app.get('/wap', function(req, res){
    res.render('wap/index',{title: '书虫手机版首页'});
})
};



